<template>
  <div>
    <el-input v-model="loginForm.username"></el-input>
    <el-input v-model="loginForm.password"></el-input>
    <el-button @click="login">登陆</el-button>
  </div>
</template>
<script>
export default {
  data() {
    return {
      loginForm: {
        username: "admin",
        password: "123"
      }
    };
  },
  methods: {
    //   登陆事件
    login() {
      this.$axios.post("/login", this.loginForm).then(res => {
        // console.log(res);
        if (res) {
            // 路由跳转，存储token
          this.$router.push({ path: "/home" });
          window.sessionStorage.setItem("token", res.data.data.token);
        }
      });
    }
  }
};
</script>